package com.xxx.common.service.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xxx.common.entity.Project;
import com.xxx.common.mapper.ProjectMapper;
import com.xxx.common.service.ProjectService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 */
@Service
public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> implements ProjectService {

    @Autowired
    private ProjectMapper projectMapper;

    @Override
    public PageInfo<Project> selectProjectInfo(Project project, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        QueryWrapper<Project> wrapper = new QueryWrapper<>();
        if (project.getType() !=null){
            wrapper.eq("type",project.getType());
        }
        if (project.getName() !=null){
            wrapper.like("name",project.getName());
        }
        if (project.getCode() !=null){
            wrapper.like("code",project.getCode());
        }
        List<Project> data = projectMapper.selectList(wrapper);
        return new PageInfo<>(data);
    }

    @Override
    public Integer saveAndUpdateProjectInfo(Project project) {
        if (project.getId() == null){
            return projectMapper.insert(project);
        }else {
            return projectMapper.updateById(project);
        }
    }

    @Override
    public Integer delProjectInfo(Integer id) {
        return projectMapper.deleteById(id);
    }
}
